package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAward;
import com.ruoyi.system.service.ISysAwardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 获奖信息Controller
 * 
 * @author ming
 * @date 2022-02-10
 */
@RestController
@RequestMapping("/system/award")
public class SysAwardController extends BaseController
{
    @Autowired
    private ISysAwardService sysAwardService;

    /**
     * 查询获奖信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:award:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAward sysAward)
    {
        startPage();
        List<SysAward> list = sysAwardService.selectSysAwardList(sysAward);
        return getDataTable(list);
    }

    /**
     * 导出获奖信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:award:export')")
    @Log(title = "获奖信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAward sysAward)
    {
        List<SysAward> list = sysAwardService.selectSysAwardList(sysAward);
        ExcelUtil<SysAward> util = new ExcelUtil<SysAward>(SysAward.class);
        util.exportExcel(response, list, "获奖信息数据");
    }

    /**
     * 获取获奖信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:award:query')")
    @GetMapping(value = "/{awardId}")
    public AjaxResult getInfo(@PathVariable("awardId") Long awardId)
    {
        return AjaxResult.success(sysAwardService.selectSysAwardByAwardId(awardId));
    }

    /**
     * 新增获奖信息
     */
    @PreAuthorize("@ss.hasPermi('system:award:add')")
    @Log(title = "获奖信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAward sysAward)
    {
        return toAjax(sysAwardService.insertSysAward(sysAward));
    }

    /**
     * 修改获奖信息
     */
    @PreAuthorize("@ss.hasPermi('system:award:edit')")
    @Log(title = "获奖信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAward sysAward)
    {
        return toAjax(sysAwardService.updateSysAward(sysAward));
    }

    /**
     * 删除获奖信息
     */
    @PreAuthorize("@ss.hasPermi('system:award:remove')")
    @Log(title = "获奖信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{awardIds}")
    public AjaxResult remove(@PathVariable Long[] awardIds)
    {
        return toAjax(sysAwardService.deleteSysAwardByAwardIds(awardIds));
    }
}
